import {
  appStart,
  createBrowserWindow,
  handleIpcMainSync,
} from "albert.gao/default/electron-main";
import { app } from "electron";
import { runServer } from "./vue-server";
(async () => {
  app.isPackaged && runServer();
  await appStart({
    onAllClosed: () => createMainWindow(),
  });
  createMainWindow();
  function createMainWindow() {
    createBrowserWindow({
      url: "http://localhost:3000",
      setConfig: (config) => {
        if (config.webPreferences) {
          Object.assign(config, {
            width: 525,
            height: 520,
            resizable: false,
            frame: true,
            closable: false,
            maximizable: false,
            autoHideMenuBar: true,
          });
          config.webPreferences.nodeIntegration = true;
          config.webPreferences.contextIsolation = false;
        }
        return config;
      },
    });
  }
  handleIpcMainSync([
    {
      route: "kill-app",
      func: () => app.exit(),
    },
  ]);
})();
